function fetch(url, method, data, ct = 'application/json') {
	return new Promise((resolve, reject) => {
		uni.request({
			url:'/api'+url,
			// url: getApp().globalData.apiUrl + url,
			method: method,
			data: data,
			header: {
				'content-type': ct,
				'Authorization': uni.getStorageSync('token')
			},
			success: (res) => {
				if (res.statusCode == 200) {
					uni.setStorageSync('token',"Bearer"+  res.header.token)
					switch(res.data.code) {
						case 401:
						uni.showToast({
							title: '登录过期',
							image: '/static/wrong.png',
							mask: true
						})
						setTimeout(() => {
							uni.reLaunch({
								url: '/pages/login/login'
							})
						}, 1500)
						break;
						case 402:
						uni.showToast({
							title: '登录过期',
							image: '/static/wrong.png',
							mask: true
						})
						setTimeout(() => {
							uni.reLaunch({
								url: '/pages/login/login'
							})
						}, 1500)
						break;
						case 500:
						uni.showToast({
							title: '服务内部错误',
							image: '/static/wrong.png',
						})
						reject(res.data)
						break;
						case 200:
						resolve(res.data)
						break;
						default:
						reject(res.data)
						break;
					}
				} else {
					uni.showToast({
						title: res.statusCode,
						image: '/static/wrong.png'
					})
					reject(res)
				}
			},
			fail: (err) => {
				uni.showToast({
					title: '响应失败!',
					image: '/static/wrong.png'
				})
			}
		})
	})
}

module.exports = {
	fetch
}